<h1><?php echo $fund['name'] ?></h1>
<ul id="breadcrumb">
	<li>งบแสดงฐานะการเงิน</li>			
</ul>
<div id="content">
	<div class="search">
		<form method="get">
		&nbsp;&nbsp;<label>ปีงบประมาณ </label><?php echo form_dropdown('year', get_year_option('2550'),(!empty($_GET['year']))?$_GET['year']:''); ?>
		<?php if(level_data('view')): ?>
		&nbsp;&nbsp;<label>หน่วยงาน </label><?php echo form_dropdown('agency_id', get_agency_option($fund['id']),(!empty($_GET['agency_id']))?$_GET['agency_id']:'','','ทั้งหมด'); ?>
		<?php endif; ?>
			&nbsp;<input type="submit" value="<?php echo lang('search'); ?>" class="button" />
		</form>
	</div>
	<div class="head">
		<p><?php echo $fund['name'] ?></p>
		<p>งบแสดงผลการดำเนินงาน</p>
		<p>ประจำปี  ตั้งแต่ <?php echo db_to_th($start_date) ?>  ถึง  <?php echo db_to_th($end_date) ?></p>
	</div>
<table class="list">
	<tr>
		<th></th>
		<th><strong><?php echo (!empty($_GET['year']))?$_GET['year']:date('Y')+543 ?></strong></th>
		<th><strong><?php echo (!empty($_GET['year']))?$_GET['year']-1:date('Y')+542 ?></strong></th>
	</tr>
	<?php $category_id = 0; ?>
	<?php $type_id = 0; ?>
	<?php $sum[1]= 0; ?>
	<?php $sum[2]= 0; ?>
	<?php $sum[3] = 0; ?>
	<?php $sum2[1]= 0; ?>
	<?php $sum2[2]= 0; ?>
	<?php $sum2[3] = 0; ?>
	
	<?php foreach($result as $item): ?>
	
	<?php if(($item['category_id']<>$category_id)&&($item['category_id']=='1')): ?>
	<tr>
		<td><strong>สินทรัพย์</strong></td>
		<td></td>
		<td></td>
	</tr>
	<?php endif; ?>
	<?php if(($item['type_id']<>$type_id)&&($item['type_id']=='1')): ?>
	<tr>
		<td><strong>สินทรัพย์หมุนเวียน</strong></td>
		<td></td>
		<td></td>
	</tr>
	<?php endif; ?>
	<?php if(($item['type_id']<>$type_id)&&($item['type_id']=='2')): ?>
	<tr>
		<td>รวมสินทรัพย์หมุนเวียน</td>
		<td class="num"><?php echo number_format($sum['1_1'],2) ?></td>
		<td class="num"><?php echo number_format($sum2['1_1'],2) ?></td>
	</tr>
	<tr>
		<td><strong>สินทรัพย์ไม่หมุนเวียน</strong></td>
		<td></td>
		<td></td>
	</tr>
	<?php endif; ?>
	
	
	
	<?php if(($item['category_id']<>$category_id)&&($item['category_id']=='2')): ?>
	<tr>
		<td>รวมสินทรัพย์ไม่หมุนเวียน</td>
		<td class="num"><?php echo number_format($sum['1_2'],2) ?></td>
		<td class="num"><?php echo number_format($sum2['1_2'],2) ?></td>
	</tr>
	<tr>
		<td>                <strong>รวมสินทรัพย์</strong></td>
		<td class="num"><?php echo number_format($sum[1],2) ?></td>
		<td class="num"><?php echo number_format($sum2[1],2) ?></td>
	</tr>
	<tr>
		<td><strong>หนี้สิน</strong></td>
		<td></td>
		<td></td>
	</tr>
	<?php endif; ?>
	<?php if(($item['type_id']<>$type_id)&&($item['type_id']=='3')): ?>
	<tr>
		<td><strong>หนี้สินหมุนเวียน</strong></td>
		<td></td>
		<td></td>
	</tr>
	<?php endif; ?>
	
	<?php if(($item['type_id']<>$type_id)&&($item['type_id']=='4')): ?>
	<tr>
		<td>รวมหนี้สินหมุนเวียน</td>
		<td class="num"><?php echo number_format($sum['2_3'],2) ?></td>
		<td class="num"><?php echo number_format($sum2['2_3'],2) ?></td>
	</tr>
	<tr>
		<td><strong>หนี้สินไม่หมุนเวียน</strong></td>
		<td></td>
		<td></td>
	</tr>
	<?php endif; ?>
	
	<?php if(($item['category_id']<>$category_id)&&($item['category_id']=='3')): ?>
	<tr>
		<td>รวมหนี้สินไม่หมุนเวียน</td>
		<td class="num"><?php echo number_format(@$sum['2_4'],2) ?></td>
		<td class="num"><?php echo number_format(@$sum2['2_4'],2) ?></td>
	</tr>
	<tr>
		<td>                <strong>รวมหนี้สิน</strong></td>
		<td class="num"><?php echo number_format($sum[2],2) ?></td>
		<td class="num"><?php echo number_format($sum2[2],2) ?></td>
	</tr>
	<tr>
		<td><strong>สินทรัพย์สุทธิ/ส่วนทุน</strong></td>
		<td></td>
		<td></td>
	</tr>
	<?php endif; ?>
	
	<tr>
		<td>    -<?php echo $item['name'] ?></td>
		<td class="num"><?php echo ($item['price']>0)?number_format($item['price'],2):'-' ?></td>
		<td class="num"><?php echo ($item['price2']>0)?number_format($item['price2'],2):'-' ?></td>
	</tr>
	<?php $category_id = $item['category_id'] ?>
	<?php $type_id = $item['type_id'] ?>
	<?php if(isset($sum[$category_id.'_'.$type_id])){$sum[$category_id.'_'.$type_id] += $item['price'];}else{$sum[$category_id.'_'.$type_id] = $item['price'];} ?>
	<?php $sum[$category_id] += $item['price'] ?>
	<?php if(isset($sum2[$category_id.'_'.$type_id])){$sum2[$category_id.'_'.$type_id] += $item['price2'];}else{$sum2[$category_id.'_'.$type_id] = $item['price2'];} ?>
	<?php $sum2[$category_id] += $item['price2'] ?>
	<?php endforeach; ?>
	<tr>
		<td>                <strong>รวมส่วนทุน</strong></td>
		<td class="num"><?php echo number_format($sum[3],2) ?></td>
		<td class="num"><?php echo number_format($sum2[3],2) ?></td>
	</tr>
</table>
</div>